home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / SHADER / SHDR / SHDRDLL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  2.9 KB  |  111 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: ShdrDll.cpp 1.2 1996/07/23 21:41:55 Damien Exp $ */
  3. //
  4. // Functions used by the DLL
  5. //
  6.  
  7. #ifndef __SHDRDLL__
  8. #include "Shdrdll.h"
  9. #endif
  10.  
  11. #ifndef __CHECKER__
  12. #include "Checker.h"
  13. #endif
  14.  
  15. #ifndef __RAINBOW__
  16. #include "Rainbow.h"
  17. #endif
  18.  
  19. #ifndef __SHDRFAC__
  20. #include "ShdrFac.h"
  21. #endif
  22.  
  23. #ifndef __3DCOFAIL__
  24. #include "3DCoFail.h"
  25. #endif
  26.  
  27. STDAPI DllInitRDCom(IShUtilities* shellUtilities) {
  28.     InitCoFailure(shellUtilities);
  29.     return S_OK;
  30.     }
  31.  
  32. //------------------------------------------------------------------------
  33. /*
  34.  * DllGetClassObject
  35.  *
  36.  * Purpose:
  37.  *  Provides an IClassFactory for a given CLSID that this DLL is
  38.  *  registered to support.  This DLL is placed under the CLSID
  39.  *  in the registration database as the InProcServer.
  40.  *
  41.  * Parameters:
  42.  *  clsID           REFCLSID that identifies the class factory
  43.  *                  desired.  Since this parameter is passed this
  44.  *                  DLL can handle any number of objects simply
  45.  *                  by returning different class factories here
  46.  *                  for different CLSIDs.
  47.  *
  48.  *  riid            REFIID specifying the interface the caller wants
  49.  *                  on the class object, usually IID_ClassFactory.
  50.  *
  51.  *  ppv             LPVOID FAR* in which to return the interface
  52.  *                  pointer.
  53.  *
  54.  * Return Value:
  55.  *  HRESULT         NOERROR on success, otherwise an error code.
  56.  */
  57.  
  58. STDAPI DllGetClassObject(REFCLSID rclsid
  59.     , REFIID riid, LPVOID FAR* ppv) {
  60.   if ((!IsEqualCLSID(rclsid, CLSID_CheckerShader))
  61.      &&(!IsEqualCLSID(rclsid, CLSID_RainbowShader)))
  62.       return ResultFromScode(E_FAIL);
  63.  
  64.   //Check that we can provide the interface
  65.   if (!IsEqualIID(riid, IID_IUnknown) && !IsEqualIID(riid, IID_IClassFactory))
  66.       return ResultFromScode(E_NOINTERFACE);
  67.  
  68.   //Return our IClassFactory for the correct Shader objects
  69.   if (IsEqualCLSID(rclsid,CLSID_CheckerShader))
  70.       *ppv=(LPVOID) new CheckerClassFactory();
  71.   else
  72.     *ppv=(LPVOID) new RainbowClassFactory();
  73.  
  74.   if (*ppv == NULL)
  75.       return ResultFromScode(E_OUTOFMEMORY);
  76.  
  77.   //AddRef the object through any interface we return
  78.   ((LPUNKNOWN)*ppv)->AddRef();
  79.  
  80.   return NOERROR;
  81.   }
  82.  
  83.  
  84. /*
  85.  * DllCanUnloadNow
  86.  *
  87.  * Purpose:
  88.  *  Answers if the DLL can be freed, that is, if there are no
  89.  *  references to anything this DLL provides.
  90.  *
  91.  * Parameters:
  92.  *  None
  93.  *
  94.  * Return Value:
  95.  *  BOOL            TRUE if nothing is using us, FALSE otherwise.
  96.  */
  97.  
  98. STDAPI DllCanUnloadNow() {
  99.   SCODE   sc;
  100.  
  101.   //Our answer is whether there are any object or locks
  102.   sc=(0L==global_count_Obj && 0L==global_count_Lock) ? S_OK : S_FALSE;
  103.   return ResultFromScode(sc);
  104.   }
  105.  
  106. //------------------------------------------------------------------------
  107. //Count number of objects and number of locks.
  108. long       global_count_Obj  = 0;
  109. long       global_count_Lock = 0;
  110.  
  111.